﻿using System;
using System.ComponentModel;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DiscoveryLogic.UI.Charts.Converters
{
    public class CornerRadiusConverter:TypeConverter 
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return true;
        }

        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            String[] radius = value.ToString().Split(',');

            CornerRadius cornerRadius;

            if (radius.Length == 1)
            {
                cornerRadius = new CornerRadius(Convert.ToDouble(radius[0], System.Globalization.CultureInfo.InvariantCulture), Convert.ToDouble(radius[0], System.Globalization.CultureInfo.InvariantCulture), Convert.ToDouble(radius[0], System.Globalization.CultureInfo.InvariantCulture), Convert.ToDouble(radius[0], System.Globalization.CultureInfo.InvariantCulture));
            }
            else if (radius.Length == 4)
            {
                cornerRadius = new CornerRadius(Convert.ToDouble(radius[0], System.Globalization.CultureInfo.InvariantCulture), Convert.ToDouble(radius[1], System.Globalization.CultureInfo.InvariantCulture), Convert.ToDouble(radius[2], System.Globalization.CultureInfo.InvariantCulture), Convert.ToDouble(radius[3], System.Globalization.CultureInfo.InvariantCulture));
            }
            else
                throw new NotSupportedException("Incorrect property value of property CornerRadius");

            return cornerRadius;
        }
    }
}
